{{#packageName}}
package {{packageName}};
{{/packageName}}

import static {{packageName}}.{{serviceName}}Grpc.getServiceDescriptor;
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;


{{#deprecated}}
@java.lang.Deprecated
{{/deprecated}}
@javax.annotation.Generated(
value = "by ReactorGrpc generator",
comments = "Source: {{protoName}}")
public final class {{className}} {
    private {{className}}() {}

    public static Reactor{{serviceName}}Stub newReactorStub(io.grpc.Channel channel) {
        return new Reactor{{serviceName}}Stub(channel);
    }

    {{#javaDoc}}
    {{{javaDoc}}}
    {{/javaDoc}}
    public static final class Reactor{{serviceName}}Stub extends io.grpc.stub.AbstractStub<Reactor{{serviceName}}Stub> {
        private {{serviceName}}Grpc.{{serviceName}}Stub delegateStub;

        private Reactor{{serviceName}}Stub(io.grpc.Channel channel) {
            super(channel);
            delegateStub = {{serviceName}}Grpc.newStub(channel);
        }

        private Reactor{{serviceName}}Stub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
            super(channel, callOptions);
            delegateStub = {{serviceName}}Grpc.newStub(channel).build(channel, callOptions);
        }

        @Override
        protected Reactor{{serviceName}}Stub build(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
            return new Reactor{{serviceName}}Stub(channel, callOptions);
        }

        {{#methods}}
            {{#javaDoc}}
        {{{javaDoc}}}
            {{/javaDoc}}
            {{#deprecated}}
        @java.lang.Deprecated
            {{/deprecated}}
        public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}reactor.core.publisher.Flux{{/isManyInput}}{{^isManyInput}}reactor.core.publisher.Mono{{/isManyInput}}<{{inputType}}> reactorRequest) {
            return com.salesforce.reactorgrpc.stub.ClientCalls.{{reactiveCallsMethodName}}(reactorRequest, delegateStub::{{methodNameCamelCase}}, getCallOptions());
        }

        {{/methods}}
        {{#unaryRequestMethods}}
            {{#javaDoc}}
        {{{javaDoc}}}
           {{/javaDoc}}
           {{#deprecated}}
        @java.lang.Deprecated
           {{/deprecated}}
        public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodName}}({{inputType}} reactorRequest) {
           return com.salesforce.reactorgrpc.stub.ClientCalls.{{reactiveCallsMethodName}}(reactor.core.publisher.Mono.just(reactorRequest), delegateStub::{{methodNameCamelCase}}, getCallOptions());
        }

        {{/unaryRequestMethods}}
    }

    {{#javaDoc}}
    {{{javaDoc}}}
    {{/javaDoc}}
    public static abstract class {{serviceName}}ImplBase implements io.grpc.BindableService {

        {{#methods}}
        {{^isManyInput}}
            {{#javaDoc}}
        {{{javaDoc}}}
            {{/javaDoc}}
            {{#deprecated}}
        @java.lang.Deprecated
            {{/deprecated}}
        public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodNameCamelCase}}({{inputType}} request) {
            return {{methodNameCamelCase}}(reactor.core.publisher.Mono.just(request));
        }
        {{/isManyInput}}

            {{#javaDoc}}
        {{{javaDoc}}}
            {{/javaDoc}}
            {{#deprecated}}
        @java.lang.Deprecated
            {{/deprecated}}
        public {{#isManyOutput}}reactor.core.publisher.Flux{{/isManyOutput}}{{^isManyOutput}}reactor.core.publisher.Mono{{/isManyOutput}}<{{outputType}}> {{methodNameCamelCase}}({{#isManyInput}}reactor.core.publisher.Flux{{/isManyInput}}{{^isManyInput}}reactor.core.publisher.Mono{{/isManyInput}}<{{inputType}}> request) {
            throw new io.grpc.StatusRuntimeException(io.grpc.Status.UNIMPLEMENTED);
        }

        {{/methods}}
        @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
            return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
                    {{#methods}}
                    .addMethod(
                            {{packageName}}.{{serviceName}}Grpc.get{{methodNamePascalCase}}Method(),
                            {{grpcCallsMethodName}}(
                                    new MethodHandlers<
                                            {{inputType}},
                                            {{outputType}}>(
                                            this, METHODID_{{methodNameUpperUnderscore}})))
                    {{/methods}}
                    .build();
        }

        protected io.grpc.CallOptions getCallOptions(int methodId) {
            return null;
        }

        protected Throwable onErrorMap(Throwable throwable) {
            return com.salesforce.reactorgrpc.stub.ServerCalls.prepareError(throwable);
        }
    }

    {{#methods}}
    public static final int METHODID_{{methodNameUpperUnderscore}} = {{methodNumber}};
    {{/methods}}

    private static final class MethodHandlers<Req, Resp> implements
            io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
            io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
            io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
            io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
        private final {{serviceName}}ImplBase serviceImpl;
        private final int methodId;

        MethodHandlers({{serviceName}}ImplBase serviceImpl, int methodId) {
            this.serviceImpl = serviceImpl;
            this.methodId = methodId;
        }

        @java.lang.Override
        @java.lang.SuppressWarnings("unchecked")
        public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
            switch (methodId) {
                {{#methods}}
                {{^isManyInput}}
                case METHODID_{{methodNameUpperUnderscore}}:
                    com.salesforce.reactorgrpc.stub.ServerCalls.{{reactiveCallsMethodName}}(({{inputType}}) request,
                            (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver,
                            serviceImpl::{{methodNameCamelCase}}, serviceImpl::onErrorMap);
                    break;
                {{/isManyInput}}
                {{/methods}}
                default:
                    throw new java.lang.AssertionError();
            }
        }

        @java.lang.Override
        @java.lang.SuppressWarnings("unchecked")
        public io.grpc.stub.StreamObserver<Req> invoke(io.grpc.stub.StreamObserver<Resp> responseObserver) {
            switch (methodId) {
                {{#methods}}
                {{#isManyInput}}
                case METHODID_{{methodNameUpperUnderscore}}:
                    return (io.grpc.stub.StreamObserver<Req>) com.salesforce.reactorgrpc.stub.ServerCalls.{{reactiveCallsMethodName}}(
                            (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver,
                            serviceImpl::{{methodNameCamelCase}}, serviceImpl::onErrorMap, serviceImpl.getCallOptions(methodId));
                {{/isManyInput}}
                {{/methods}}
                default:
                    throw new java.lang.AssertionError();
            }
        }
    }

}
